/*
 * Copyright (c) 2017. 深圳一七科技. All rights reserved.
 */

package com.yiqi.liebang.feature.home.presenter;

import com.amap.api.maps2d.MapView;
import com.yiqi.liebang.entity.bo.CouponBo;
import com.yiqi.liebang.entity.bo.OrderBo;
import com.yiqi.liebang.entity.bo.PageBo;
import com.yiqi.liebang.entity.bo.SearchBo;
import com.yiqi.liebang.entity.bo.TopicBo;
import com.yiqi.liebang.entity.bo.TopicListBo;
import com.yiqi.liebang.feature.home.contract.TopicContract;
import com.yiqi.liebang.feature.home.dependencies.home.DaggerHomePresenterComponent;
import com.yiqi.liebang.feature.home.dependencies.topic.DaggerTopicPresenterComponent;
import com.yiqi.liebang.feature.mine.contract.CouponContract;
import com.yiqi.liebang.feature.mine.dependencies.coupon.DaggerCouponPresenterComponent;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * LIJUWEN
 *
 * @email yiyayiyayaoljw@gmail.com
 * @date 2018/7/11 9:31
 */
public class TopicPresenter implements TopicContract.Presenter {

    private TopicContract.View mView;

    @Inject

    TopicContract.Model mModel;


    public TopicPresenter(TopicContract.View mView) {
        this.mView = mView;
        DaggerTopicPresenterComponent.create().inject(this);
    }

    @Override
    public void start() {

    }

    @Override
    public void getTopicList(String classifyId, String serviceType, String classify2Id, String IntelligentType, int pageIndex, int pageSize) {
        mModel.getTopicList(new TopicListBo(classifyId,serviceType,classify2Id,IntelligentType,pageIndex, pageSize))
                .compose(mView.bindToLife()).subscribe(new Observer<List<TopicBo>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(List<TopicBo> couponBoPageData) {
                if (couponBoPageData!=null&&couponBoPageData.size()>0){
                    mView.showTopicListSuccess(couponBoPageData);
                }else {
                    mView.showTopicListEmpty();
                }
            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showTopicListError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void getTopicListMore(String classifyId, String serviceType, String classify2Id, String IntelligentType, int pageIndex, int pageSize) {
        mModel.getTopicList(new TopicListBo(classifyId,serviceType,classify2Id,IntelligentType,pageIndex, pageSize))
                .compose(mView.bindToLife()).subscribe(new Observer<List<TopicBo>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(List<TopicBo> couponBoPageData) {
               mView.showTopicListMoreSuccess(couponBoPageData);
            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showTopicListMoreError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void searchTopic(String content, int pageIndex, int pageZize) {
        mModel.searchTopic(new SearchBo(content,pageIndex, pageZize))
                .compose(mView.bindToLife()).subscribe(new Observer<List<TopicBo>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(List<TopicBo> couponBoPageData) {
                if (couponBoPageData!=null&&couponBoPageData.size()>0){
                    mView.showTopicListSuccess(couponBoPageData);
                }else {
                    mView.showTopicListEmpty();
                }
                mView.dismissLoading();
            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showTopicListError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void searchMore(String content, int pageIndex, int pageZize) {
        mModel.searchTopic(new SearchBo(content,pageIndex, pageZize))
                .compose(mView.bindToLife()).subscribe(new Observer<List<TopicBo>>() {
            @Override
            public void onSubscribe(Disposable d) {
            }

            @Override
            public void onNext(List<TopicBo> couponBoPageData) {
                mView.showTopicListMoreSuccess(couponBoPageData);
            }

            @Override
            public void onError(Throwable e) {
                mView.showTopicListMoreError(e.getMessage());
            }

            @Override
            public void onComplete() {

            }
        });
    }




}
